<?php
use Entities\Materiais;
$tipoBusca = $_REQUEST['tipoBusca'];
$strBusca = $_REQUEST['strBusca'];

$dql = "select c from Entities\Materiais c where 1=1 ";
switch ($tipoBusca){
	case "nome":
		$dql .= " and c.descricao like :parametro";
		$strBusca = "%$strBusca%";
		break;
	default:
		$dql .= " and 1>2";
}
$q = $em->createQuery($dql);
$q->setParameter("parametro", $strBusca);
$materiais = $q->getResult();
$xml = "";
foreach ($materiais as $material){
	$xml .= "<material>";
	$xml .= "<id>".$material->getId()."</id>";
	$xml .= "<descricao>".$material->getDescricao()."</descricao>";
	
	$xml .= "<validade>".$material->getTempoValidade()."</validade>";
	$xml .= "<ca>".$material->getCa()."</ca>";
	$xml .= "</material>";
}

echo $xml;